package com.itheima.admin.controller;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.PageVo;
import com.itheima.Result;
import com.itheima.admin.dto.DeptDto;
import com.itheima.admin.pojo.Dept;
import com.itheima.admin.service.IDeptService;
import com.itheima.admin.vo.DeptPageVo;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    private IDeptService deptService;
    @ApiOperation("部门条件分页查询")
    @PostMapping("/list")
    public PageVo<DeptPageVo> queryByPage(@RequestBody DeptDto deptDto){
        if(deptDto.getCurrentPage()==null){
            deptDto.setCurrentPage(1);
        }
        if(deptDto.getPageSize()==null){
            deptDto.setPageSize(10);
        }
        return deptService.queryByPage(deptDto);
    }

    @GetMapping("/listall")
    public List<Dept> selectAll(){
        List<Dept> depts = deptService.selectAll();
        return depts;
    }

    @PostMapping("/add")
    public Result insertDept(@RequestBody Dept dept){
        boolean result = deptService.insertDept(dept);
        return new Result(result,result?"添加用户成功":"添加用户失败",null);
    }

    @DeleteMapping("/{id}")
    public Result deleteDeptById(String id){
        boolean result = deptService.deleteDeptById(id);
        return new Result(result,result?"删除用户成功":"删除用户失败",null);
    }




}
